package fr.red5.managers
{
	import fr.red5.net.Red5Connection;
	import fr.red5.managers.UserManager;
	import fr.red5.events.*
	
	import mx.containers.*;
	import mx.controls.*;
	import mx.core.*;
	import flash.events.*;
	import flash.utils.setTimeout
	
	[DefaultProperty("innerChildren")]
	
	public class Session extends Box
	{
		public static var version:String = "0.1";
		
		private var _innerChildren:Array = [];
		
		protected var sessionID:String;
		private var _url:String = "";
				
		private var connection:Red5Connection;
		private var userManager:UserManager;
		
		
		public function Session(){
			super();
			connection = new Red5Connection();
			connection.addEventListener(ConnectionSuccessEvent.CONNECT_SUCCESS,onConnect);
			connection.addEventListener("setUserId",onSessionID);
		}
		
		public function set url(value:String):void {
			_url = value;
			connection.server = value;
			connection.connect();
		}
		
		public function get url():String {
			return _url;
		}
		
		public function onConnect(event:ConnectionSuccessEvent):void {
			Alert.show("onConnect");
			userManager = new UserManager(connection);
		}
		
		public function onSessionID(event:CallBackEvent):void {
			Alert.show("Session ID"+event.data);
		}
		

		public function set innerChildren(value:Array):void
		{
			_innerChildren = value;
			assignInnerChildren();
		}
		
		public function get innerChildren():Array
		{
			return _innerChildren;
		}
		
		private function assignInnerChildren():void
		{
			removeAllChildren();
			for(var i:int = 0;i<_innerChildren.length;i++)
			{
				_innerChildren[i].owner = this
				addChild(_innerChildren[i]);
				
			}				
		}
		
		override protected function createChildren():void
		{
			super.createChildren();
			assignInnerChildren();
		}
			
	}
}